﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public static GameManager Instance => instance;
    private static GameManager instance;

    public bool IsGameStarted { get; set; } = false;

    public bool IsGameOver { get; set; } = false;

    public bool IsPause { get; set; } = false;

    public int GameScore { get; set; } = 0;

    public bool IsPlayerMove { get; set; } = false;


    private void Awake()
    {
        instance = this;

        EventCenter.AddListener(EventType.AddScore, AddScore);
        EventCenter.AddListener(EventType.PlayerMove, PlayerMove);
    }

    private void OnDestroy()
    {
        EventCenter.RemoveListener(EventType.AddScore, AddScore);
        EventCenter.RemoveListener(EventType.PlayerMove, PlayerMove);
    }

    private void AddScore()
    {
        if (IsGameStarted && !IsGameOver && !IsPause)
        {
            GameScore++;
            EventCenter.Broadcast<int>(EventType.UpdateScore, GameScore);
        }
    }

    private void PlayerMove()
    {
        IsPlayerMove = true;
    }
}
